import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import {UtilService} from "../my-service/util.service";

@Injectable()
export class EnterGuard implements CanActivate {
  constructor(
    private utilService: UtilService
  ) { }
  canActivate() {
    return this.utilService.getUserInfo().then(userInfo => {
      if(userInfo.status !== 1) return false;
      return this.utilService.isCanEnterApp(userInfo.userGuid).then(allow => {
        if (allow.code === 1) return true;
        else {
          this.utilService.remind('error', '你还未购买此应用');
          setTimeout( () => {
            window.location.href = 'https://www.lessonplan.cn';
          }, 2000);
          return false;
        }
      })
    })
  }

}
